<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <script>
    $(document).ready(function(){
    });
    
 	// 检索按钮实装方法
	function searchListForm() {
		$("#activity_pane").showLoading();
		var params = {"qcItem":$("#qcItem").val()};
		$.post("${ctx}/check/quality/selectQualityItem", params, function(result) {
			$("#listHtml").html($(callBackHtml(result)).find("#listHtml").html());
			$("#activity_pane").hideLoading();
		}, 'html');
	} 
   
 	function clean(){
 		$("#qcItem").val("");
 		searchListForm();
 	}
 	
    // 选择质检项目 
    function selectItem() {
    	//获取 iframe 数量 
    	var frLength = window.parent.frames.length;
    	//父画面下标  
    	var parentIndex = frLength-2;
    	var trList = $("#listHtml tr.trSelected");
    	var parentTrList = window.parent.frames[parentIndex].$("#tableId tr");
    	var operatingId = window.parent.frames[parentIndex].$("#operatingId").val();
    	var flag = "false";
    	var alertMessage = "";
    	var count = 0;
    	$.each(trList,function(i, e) {
    		$.each(parentTrList,function(j, f) {
    			if($(e).find(".qcId").val() ==  $(f).find(".qcId").val()){
    				alertMessage += ++count+ "."+$(e).find(".qcItem").val() + "\n"
    				flag = "true";
    				return true;
    			}
    		});
		});
    	if (flag == "true") {
    		alert(alertMessage+"以上 "+count+" 个项目已存在！");
			return;
		}
    	$.each(trList,function(i, e) {
    		var html = "";
    		html += "<tr class='none'>";
    		html += "<input type='hidden' class='qcId' name='qcList[tempIndex].qcId' value='"+$(e).find(".qcId").val()+"'/>";
    		html += "<input type='hidden' class='operatingId' name='qcList[tempIndex].operatingId' value='"+operatingId+"'/>";
    		html += "<input type='hidden' class='qcItem' name='qcList[tempIndex].qcItem' value='"+$(e).find(".qcItem").val()+"'/>";
    		html += "<input type='hidden' class='qcItemCd' name='qcList[tempIndex].qcItemCd' value='"+$(e).find(".qcItemCd").val()+"'/>";
    		html += "<input type='hidden' class='qcItemValue' name='qcList[tempIndex].qcItemValue' value='"+$(e).find(".qcItemValue").val()+"'/>";
    		html += "</tr>";
    		window.parent.frames[parentIndex].$("#tableId").append(html);
    	});
    	window.parent.frames[parentIndex].refreshHtml();
        closeWin();
	}
    
    //选择按钮事件
    function selectFunction(obj){
    	// 判断是否被选中
    	var bolSelected = $(obj).hasClass("trSelected");
    	if (bolSelected) {
    		$(obj).removeClass("trSelected");
    	} else {
    		$(obj).addClass("trSelected");
    	}
    }
    
    /* 删除 项目  */
	function deleteCurrentRow(obj,qcId){ 
	 	if (confirm("确定删除该质检项目吗？")) {
	 		var param = {"qcId" : qcId};
	 		$.post("${ctx}/check/quality/deleteItem",param,function(result){
				var tr=obj.parentNode.parentNode.parentNode;  
				$(tr).remove();
        	})
		}
	}
    
	/* 编辑 项目  */
	function editItem(obj,qcId){
		popup("600px","350px","${ctx}/check/quality/form?qcId="+qcId);
	}
    </script>
    
</head>
<body>
<form id="searchForm">
<input type="hidden" id="indentSelectFlg" name="indentSelectFlg" value="${orderMateriel.indentSelectFlg}"/>
<div class="layerHeader clearfix" style="width: 1000px">
	<p class="headerTitle">质检项目</p>
	<div class="headerButton clearfix">
	<!-- 新建项目 -->
    <button type="button" onclick="popup('600px','350px','${ctx}/check/quality/form')">新建项目</button>
	<!-- 检索 -->
    <button type="button" onclick="searchListForm();"><spring:message code="commom_check" /></button>
    <!-- 重置 -->
    <button type="button" onclick="clean();"><spring:message code="common_reset" /></button>
    <!-- 选择 -->
    <button type="button" onclick="selectItem();"><spring:message code="style_selectOK" /></button>
    <!-- 关闭 -->
    <button type="button" onclick="closeWin();"><spring:message code="btn_cancle" /></button>
    </div>
</div>
<div class="listArea" style="width: 1000px" id="activity_pane">
	<div class="listBg">
	    <div class="searchArea clearfix">
            <div class=" clearfix">
                <!-- 项目名称 -->
                <div class="searchInp clearfix">
                    <p>项目名称</p>
                    <input type="text" id="qcItem" >
                </div>
            </div>
        </div>
	
        <div class="tableArea tabBoxSm" >
            <div class="tableScrollSm" style="overflow: auto;height: 557px;width:963px;">
                <table cellpadding="0" class="tableHead " >
                    <thead>
                    <tr>
                    	<th><p style="width:60px;">No.</p></th>
                        <th><p style="width:100px;">操作</p></th>
                        <th><p style="width:300px;">质检项目名称</p></th>
                        <th><p style="width:240px;">项目Code</p></th>	
                        <th><p style="width:240px;">项目Value</p></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" >              
                    <tbody id = "listHtml">
                    	<c:forEach items="${itemList}" var="item" varStatus="status">
						    <tr onclick="selectFunction(this)">
						    	<td><p style="width:60px;">${status.count }</p></td>
						    	<td><p style="width:100px;"><img src='${ctxStatic}/images/btn-bj.png' class="tab-cz" onclick='editItem(this,${item.qcId })'>&ensp;&ensp;<img src='${ctxStatic}/images/btn-sc.png' class="tab-cz" onclick='deleteCurrentRow(this,${item.qcId })'></p></td>
						    	<td><p style="width:300px;">${item.qcItem }</p></td>
						    	<td><p style="width:240px;">${item.qcItemCd }</p></td>
						    	<td><p style="width:240px;">${item.qcItemValue }</p></td>
						    	<input type="hidden" class="qcId" name="qcId" value="${item.qcId }"/>
						    	<input type="hidden" class="qcItem" name="qcItem" value="${item.qcItem }"/>
						    	<input type="hidden" class="qcItemCd" name="qcItemCd" value="${item.qcItemCd }"/>
						    	<input type="hidden" class="qcItemValue" name="qcItemValue" value="${item.qcItemValue }"/>
						    </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</form>
</body>
</html>